//
//  FinanciaViewController.m
//  项目三
//
//  Created by rimi on 15/9/30.
//  Copyright (c) 2015年 rimi. All rights reserved.
//


#import "FinanciaViewController.h"
#import "SaveView.h"
#import "ForeView.h"
#import "MoneyView.h"
#import "InterView.h"

@interface FinanciaViewController () {

    UIButton *_saveBtn;
    UIButton *_foreBtn;
    UIButton *_moneyBtn;
    UIButton *_interBtn;
}

@property (nonatomic, strong) SaveView *saveView;
@property (nonatomic, strong) ForeView *foreView;
@property (nonatomic, strong) MoneyView *moneyView;
@property (nonatomic, strong) InterView *interView;

@end

@implementation FinanciaViewController
#pragma mark - 生命周期

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeUserInterface];
}

#pragma mark - privte methods

#pragma mark - init
- (void)initializeUserInterface {
    
    self.titleImageView.image = [UIImage imageNamed:@"金融资讯页眉_24"];
    [super initializeUserInterface];
    
    _saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_saveBtn setBackgroundImage:[UIImage imageNamed:@"存贷利率_15"] forState:UIControlStateNormal];
    [_saveBtn setBackgroundImage:[UIImage imageNamed:@"存贷利率_15-1"] forState:UIControlStateSelected];
    [_saveBtn setFrame:DHFlexibleFrame(CGRectMake(211, 24, 102, 32))];
    [_saveBtn addTarget:self action:@selector(saveBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_saveBtn];
    
    _foreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_foreBtn setBackgroundImage:[UIImage imageNamed:@"外汇贵金属_未选中"] forState:UIControlStateNormal];
    [_foreBtn setBackgroundImage:[UIImage imageNamed:@"外汇贵金属_选中"] forState:UIControlStateSelected];
    [_foreBtn setFrame:DHFlexibleFrame(CGRectMake(326, 24, 102, 32))];
    [_foreBtn addTarget:self action:@selector(foreBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_foreBtn];
    
    _moneyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_moneyBtn setBackgroundImage:[UIImage imageNamed:@"投资理财_21"] forState:UIControlStateNormal];
    [_moneyBtn setBackgroundImage:[UIImage imageNamed:@"投资理财_21-1"] forState:UIControlStateSelected];
    [_moneyBtn setFrame:DHFlexibleFrame(CGRectMake(441, 24, 102, 32))];
    [_moneyBtn addTarget:self action:@selector(moneyBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_moneyBtn];
    
    _interBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_interBtn setBackgroundImage:[UIImage imageNamed:@"未选中 附近网点"] forState:UIControlStateNormal];
    [_interBtn setBackgroundImage:[UIImage imageNamed:@"选中 附近网点"] forState:UIControlStateSelected];
    [_interBtn setFrame:DHFlexibleFrame(CGRectMake(557, 24, 102, 32))];
    [_interBtn addTarget:self action:@selector(interBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_interBtn];
    
    _saveBtn.selected = YES;
    _foreBtn.selected = NO;
    _moneyBtn.selected = NO;
    _interBtn.selected = NO;
    
    [UIView animateWithDuration:1.0 animations:^{
        self.saveView.alpha = 1;
    }];
    [self.view addSubview:self.saveView];
}

#pragma mark privte methods
- (void)saveBtnEvent:(UIButton *)sender {

    _saveBtn.selected = YES;
    _foreBtn.selected = NO;
    _moneyBtn.selected = NO;
    _interBtn.selected = NO;
    
    [self.view addSubview:self.saveView];
    [self removeView:self.foreView];
    [self removeView:self.moneyView];
    [self removeView:self.interView];
    [UIView animateWithDuration:1.0 animations:^{
        self.saveView.alpha = 1;
    }];
}

- (void)foreBtnEvent:(UIButton *)sender {
    
    _saveBtn.selected = NO;
    _foreBtn.selected = YES;
    _moneyBtn.selected = NO;
    _interBtn.selected = NO;
    
    [self removeView:self.saveView];
    [self.view addSubview:self.foreView];
    [self removeView:self.moneyView];
    [self removeView:self.interView];
    [UIView animateWithDuration:1.0 animations:^{
        self.foreView.alpha = 1;
    }];
}
- (void)moneyBtnEvent:(UIButton *)sender {
    
    _saveBtn.selected = NO;
    _foreBtn.selected = NO;
    _moneyBtn.selected = YES;
    _interBtn.selected = NO;
    
    [self.view addSubview:self.moneyView];
    [self removeView:self.foreView];
    [self removeView:self.saveView];
    [self removeView:self.interView];
    
    [UIView animateWithDuration:1.0 animations:^{
        self.moneyView.alpha = 1;
    }];
}
- (void)interBtnEvent:(UIButton *)sender {
    
    _saveBtn.selected = NO;
    _foreBtn.selected = NO;
    _moneyBtn.selected = NO;
    _interBtn.selected = YES;

    [self.view addSubview:self.interView];
    [self removeView:self.foreView];
    [self removeView:self.saveView];
    [self removeView:self.moneyView];

    [UIView animateWithDuration:1.3 animations:^{
        self.interView.alpha = 1;
    }];
}

- (void)removeView:(UIView *)view {

    [UIView animateWithDuration:0.6 animations:^{
        view.alpha = 0;
    } completion:^(BOOL finished) {
        [view removeFromSuperview];
    }];
}
#pragma mark - getter
- (SaveView *)saveView {

    if (!_saveView) {
        _saveView = [[SaveView alloc] initWithFrame:DHFlexibleFrame(CGRectMake(0, 82, 708, 944))];
        _saveView.alpha = 0;
    }
    return _saveView;
}
- (ForeView *)foreView {

    if (!_foreView) {
        _foreView = [[ForeView alloc] initWithFrame:DHFlexibleFrame(CGRectMake(0, 82, 708, 944))];
        _foreView.alpha = 0;
    }
    return _foreView;
}
- (MoneyView *)moneyView {
    
    if (!_moneyView) {
        _moneyView = [[MoneyView alloc] initWithFrame:DHFlexibleFrame(CGRectMake(0, 82, 708, 944))];
        _moneyView.alpha = 0;
    }
    return _moneyView;
}
- (InterView *)interView {

    if (!_interView) {
        _interView = [[InterView alloc] initWithFrame:DHFlexibleFrame(CGRectMake(0, 82, 708, 944))];
        _interView.alpha = 0;
    }
    return _interView;
}
@end
